
package com.huizhan.web.dao;
 
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;

import java.util.*;

import com.huizhan.web.model.*;


@Repository 
public interface TicketComplimentaryDao extends JpaRepository<TicketComplimentary,Long>
{
    
    /**
     * 根据手机号码获取用户
     * @param project_Id 项目ID
     * @param phone 手机号码
     * @param ticketTypeId 类型ID
     * @return 用户信息
     */
    TicketComplimentary findByProjectIdAndPhoneAndTicketTypeId(String projectId,String phone,Long ticketTypeId);

    /**
     * 根据手机号码获取用户
     * @param project_Id 项目ID
     * @param phone 手机号码
     * @return 用户信息
     */
    List<TicketComplimentary> findByProjectIdAndPhone(String projectId,String phone);

    /**
     * 分页查赠票集合
     * @param name 名称
     * @param phone 手机号
     * @param ticket_Type_Id 票类型ID
     * @param project_Id 项目ID
     * @param pageable 分页参数
     * @return 票种集合
     */
    @Query(
        value = "SELECT * FROM ticket_complimentary"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (phone LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (project_Id =?3 OR ?3  = '') "
            + " AND (level =?4 OR ?4 = -1 )", 
        countQuery = "SELECT COUNT(1) FROM ticket_complimentary"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (phone LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (project_Id =?3 OR ?3  = '') "
            + " AND (level =?4 OR ?4 = -1 )",
        nativeQuery = true
    )
    Page<TicketComplimentary> findByWhere(String name,String phone,String project_Id,Long level, Pageable  pageable);
}
